package api

import (
	"fmt"
	"go_code/20211009/model"
	"time"
)

var (
	Datetime string
)

func init() {
	// 获取时间
	now := time.Now()
	Datetime = now.Format("2006-01-02 15:04:05")

	fmt.Println("api模块初始化成功……")
}

func Welcome() {
	fmt.Printf("陈文小超欢迎您来到今日的golang语言学习，现在的时间是：%v\n", Datetime)
	fmt.Println("--------------------------------------------------------------")
}

func Access() {
	objectStudy()
}

// 面向对象练习
func objectStudy() {
	var student = Student{
		name:   "venki",
		gender: "男",
		age:    29,
		id:     05321,
		score:  99.99,
	}

	fmt.Println((&student).say())
	fmt.Println("---------------")

	/*var l float64
	var w float64
	var h float64
	fmt.Println("请输入立方体的长：")
	_, err := fmt.Scanln(&l)
	if err != nil {
		return
	}
	fmt.Println("请输入立方体的宽：")
	_, err = fmt.Scanln(&w)
	if err != nil {
		return
	}
	fmt.Println("请输入立方体的高：")
	_, err = fmt.Scanln(&h)
	if err != nil {
		return
	}

	var volume = Volume{
		length: l,
		width:  w,
		height: h,
	}

	fmt.Println("您输入的立方体体积是：", volume.cubage())
	fmt.Println("-----------------------------------")*/
	fmt.Println("---------------工厂模式-------------")
	stuPtr := model.NewObject("陈文小超", 29)
	fmt.Println(*stuPtr)
	fmt.Println("-------------面向对象三大特性-----------------")
}

type Volume struct {
	length float64
	width  float64
	height float64
}

func (volume *Volume) cubage() float64 {
	result := volume.length * volume.width * volume.height

	return result
}

type Student struct {
	name   string
	gender string
	age    int
	id     int
	score  float64
}

func (student *Student) say() string {
	infoStr := fmt.Sprintf("student的信息：name=[%v],gender=[%v],age=[%v],id=[%v],score=[%v]",
		student.name, student.gender, student.age, student.id, student.score)

	return infoStr
}
